package com.juzipi.demo.handler;

import com.juzipi.demo.tools.Result;
import com.juzipi.demo.tools.ResultTool;
import com.juzipi.demo.utils.JsonAuthentication;
import com.juzipi.demo.utils.ResultCode;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 *
 */
@Component
public class MySessionInformationExpiredStrategy extends JsonAuthentication implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        Result result = ResultTool.failCustomize(ResultCode.USER_ACCOUNT_USE_BY_OTHERS, null);

        this.WriteJson(sessionInformationExpiredEvent.getRequest(), sessionInformationExpiredEvent.getResponse(), result);
    }
}
